package com.xm;

import com.xm.controller.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("file:D:/毕设项目/video-file/")
                .addResourceLocations("classpath:/META-INF/resources/");
    }

    /**
     * 初始化zk客户端
     * @return
     */
    @Bean(initMethod = "init")
    public ZKCuratorClient zKCuratorClient(){
        return new ZKCuratorClient();
    }
    /**
     * 初始化拦截器
     * @return
     */
    @Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myInterceptor()).addPathPatterns("/user/**","/video/saveComments")
                //.addPathPatterns("/bgm/**")
//                .addPathPatterns("/video/userLike","/video/userUnlike")
        .excludePathPatterns("/user/login","/user/logout","/video/hot","/user/queryPublisher");
        super.addInterceptors(registry);
    }
}
